define(['jquery', 'bootstrap', 'backend','frontend', 'table', 'form','amazeui','template'], function ($, undefined, Backend,Frontend,Table, Form ,Amazeui,template) {
     var validatoroptions = {
        invalid: function (form, errors) {
            $.each(errors, function (i, j) {
                Layer.msg(j);
            });
        }
    };
    var Controller = {
        mymineral: function () {

            Table.api.init({
                extend: {
                    index_url: 'mineral/mymineral',
                }
            });
            var table = $("#table");
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                columns: [
                    [
                        {field: 'num', title: '有效广告包数量',opreat:false},
                        {field: 'total', title: '已获得广告价值',opreat:false},
                        {field: 'today', title:'当天广告价值',opreat:false},
                        {field: 'status', title: '状态',opreat:false},
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);

            $("#submission").on('click',function(){
                 var num=$("#number_advertisement").val();
                 var paypwd=$("#paypwd").val();
                 var index = layer.load();
                 $.post('mineral/buy_advertisement',{num:num,paypwd:paypwd},function(rsp){
                    layer.closeAll();
                    layer.msg(rsp.msg, {
                      offset: 'auto',
                      anim: 6,
                      end:function(){
                       
                      }
                    });
                    if (rsp.code==0) {}else{
                           window.location.reload();
                         } 
                 })
            })
            $("#transfer").on('click',function(){
                 var num=$("#transfer_num").val();
                 var paypwd=$("#pwd").val();
                 var index = layer.load();
                 $.post('mineral/transport',{num:num,paypwd:paypwd},function(rsp){
                    layer.closeAll();
                    layer.msg(rsp.msg, {
                      offset: 'auto',
                      anim: 6,
                      end:function(){
                     
                      }
                    });
                    if (rsp.code==0) {}else{
                           window.location.reload();
                         } 
                 })
            })

        },
        synergetic: function () {
            Table.api.init({
                extend: {
                    index_url: 'mineral/synergetic',
                }
            });

            var table = $("#table");
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                columns: [
                    [
                        {field: 'num', title: '数量',opreat:false},
                        {field: 'touser.username', title: '贡献者',opreat:false},
                        {field: 'createtime', title:'贡献时间',opreat:false},
                        {field: 'status', title: '状态',opreat:false},
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            $("#transportd").on('click',function(){
                 var num=$("#transportd_num").val();
                 var paypwd=$("#transportd_pwd").val();
                 var index = layer.load();
                 $.post('mineral/transportd',{num:num,paypwd:paypwd},function(rsp){
                    layer.closeAll();
                    layer.msg(rsp.msg, {
                      offset: 'auto',
                      anim: 6,
                      end:function(){
                      
                      }
                    });
                    if (rsp.code==0) {}else{
                       window.location.reload();
                     } 
                 })
            })
        },
        frame: function(){
            var shangji = 0;
            $('#return').on('click',function(){
                $.post('mineral/frame',{referee_id:shangji},function(rsp){

                    var data = {
                        list: rsp.list
                    };
                    $('#content').html(template('frametpl', data));

                    loadframe();
                })
            })

            $('#return').trigger("click");


            function loadframe() {
                $('.preframe').unbind('click').on('click',function(){
                    var referee_id = $(this).attr('data-id');
                    console.log(referee_id);
                    // $.post('mineral/frame')
                    $.post('mineral/frame',{referee_id:referee_id},function(rsp){
                        var data = {
                            list: rsp.list
                        };
                        $('#content').html(template('frametpl', data));
                        loadframe();
                    })
                })
            }

            
        },
        wallet_withdraw_money:function(){
           $("#moneytype").data("validator-options", validatoroptions);

              Form.api.bindevent($("#moneytype"), function (data, ret) {
                setTimeout(function () {
                    location.href = ret.url ? ret.url : "/";
                }, 1000);
              });
        }
    };

    return Controller;
});